# 由于 xlutils 是第三方插件，所以需要提前安装：pip install xlutils

import xlrd
from xlutils.copy import copy

print('---------------- 打开 Excel ----------------')
read_book = xlrd.open_workbook('../02.py_excelFile/电影数据.xlsx')

print('---------------- 复制数据 ----------------')
wb = copy(read_book)

print('---------------- 选择工作簿 ----------------')
sh = wb.get_sheet(0)
sh.write(5, 0, '疯狂原始人')
sh.write(5, 1, 3000)
sh.write(5, 2, '5.0')

print('---------------- 保存Excel ----------------')
sh2 = wb.add_sheet('汇总数据')
count = 0
rs = read_book.sheet_by_index(0)
for i in range(1, rs.nrows):
    num = rs.cell_value(i, 1)
    count += num

sh2.write(0, 0, '总票房')
sh2.write(0, 1, count)

wb.save('../02.py_excelFile/电影数据修改.xlsx')



